package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.CompanyCustomGroupingAddDTO;
import org.jsola.hr.dto.CompanyCustomGroupingUpdateDTO;
import org.jsola.hr.entity.CompanyCustomGroupingDO;
import org.jsola.hr.query.CompanyCustomGroupingQuery;
import org.jsola.hr.service.ICompanyCustomGroupingService;
import org.jsola.hr.vo.CompanyCustomGroupingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 自定义用工单位分组
 *
 * @author zhr
 */
@Component
public class CompanyCustomGroupingTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICompanyCustomGroupingService companyCustomGroupingService;

    /**
     * 生成add测试数据
     * @return CompanyCustomGroupingAddDTO
     */
    public CompanyCustomGroupingAddDTO getCompanyCustomGroupingAddDTO(){
        CompanyCustomGroupingAddDTO companyCustomGroupingAddDTO = new CompanyCustomGroupingAddDTO();
        companyCustomGroupingAddDTO.setName(getRandomValue("varchar",64));
        companyCustomGroupingAddDTO.setModuleCode(getRandomValue("varchar",50));
        companyCustomGroupingAddDTO.setCompanyIds(getRandomValue("text",2147483647));
        companyCustomGroupingAddDTO.setYearly(SafeKit.getInteger(getRandomValue("int",10)));
        companyCustomGroupingAddDTO.setMonthly(SafeKit.getInteger(getRandomValue("int",10)));
        return companyCustomGroupingAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CompanyCustomGroupingUpdateDTO
     */
    public CompanyCustomGroupingUpdateDTO getCompanyCustomGroupingUpdateDTO(CompanyCustomGroupingVO companyCustomGroupingVO){
        return companyCustomGroupingService.selectDOById(companyCustomGroupingVO.getId(), SITE_ID).to(CompanyCustomGroupingUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CompanyCustomGroupingQuery
     */
    public CompanyCustomGroupingQuery getCompanyCustomGroupingQuery() {
        CompanyCustomGroupingQuery companyCustomGroupingQuery = new CompanyCustomGroupingQuery();
        List<CompanyCustomGroupingDO> companyCustomGroupingDOList = companyCustomGroupingService.list(new CompanyCustomGroupingDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(companyCustomGroupingDOList)) {
            CompanyCustomGroupingDO companyCustomGroupingDO = companyCustomGroupingDOList.get(0);
            companyCustomGroupingQuery = companyCustomGroupingDO.to(CompanyCustomGroupingQuery.class);
        }
        return companyCustomGroupingQuery;
    }

    /**
     * 保存示例
     * @return CompanyCustomGroupingVO
     */
    public CompanyCustomGroupingVO saveCompanyCustomGroupingExample(){
        CompanyCustomGroupingAddDTO addDTO = this.getCompanyCustomGroupingAddDTO();
        CompanyCustomGroupingVO companyCustomGroupingVO = companyCustomGroupingService.save(addDTO,buildTokenUser());
        return companyCustomGroupingVO;
    }


}

